/*    */ package com.zimbra.cs.account.callback;
/*    */ 
/*    */ import com.google.common.collect.Sets;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.util.StringUtil;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.AliasedEntry;
/*    */ import com.zimbra.cs.account.AttributeCallback;
/*    */ import com.zimbra.cs.account.Entry;
/*    */ import com.zimbra.cs.account.Group;
/*    */ import java.util.Map;
/*    */ import java.util.Set;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class AllowAddressForDelegatedSender
/*    */   extends AttributeCallback
/*    */ {
/*    */   public void preModify(CallbackContext context, String attrName, Object attrValue, Map attrsToModify, Entry entry)
/*    */     throws ServiceException
/*    */   {
/* 43 */     if (context.isDoneAndSetIfNot(AllowAddressForDelegatedSender.class)) {
/*    */       return;
/*    */     }
/*    */     
/*    */     Set<String> allowedValues;
/* 48 */     if (entry == null) {
/* 49 */       Set<String> allowedValues = Sets.newHashSet();
/* 50 */       String entryName = context.getCreatingEntryName();
/* 51 */       if (entryName != null) {
/* 52 */         allowedValues.add(entryName);
/*    */       }
/*    */     } else {
/* 55 */       if ((!(entry instanceof Account)) && (!(entry instanceof Group))) {
/* 56 */         return;
/*    */       }
/* 58 */       allowedValues = ((AliasedEntry)entry).getAllAddrsSet();
/*    */     }
/*    */     
/* 61 */     Object replace = attrsToModify.get(attrName);
/* 62 */     Object add = attrsToModify.get("+" + attrName);
/*    */     
/*    */ 
/* 65 */     Set<String> values = getMultiValueSet(replace != null ? replace : add);
/* 66 */     for (String value : values) {
/* 67 */       if ((!StringUtil.isNullOrEmpty(value)) && (!allowedValues.contains(value))) {
/* 68 */         throw ServiceException.INVALID_REQUEST("value is not one of the addresses of the entry: " + value, null);
/*    */       }
/*    */     }
/*    */   }
/*    */   
/*    */   public void postModify(CallbackContext context, String attrName, Entry entry) {}
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/callback/AllowAddressForDelegatedSender.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */